package com.health.viewscontrols.focusgroup;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.blankj.utilcode.util.AdaptScreenUtils;
import com.health.tools.SPUtil;
import com.health.viewscontrols.NovaApplication;
import com.health.R;
import com.health.adapter.FocusGroupGridAdapter;
import com.health.tablebean.ARCHIVE_BASEINFO;
import com.nova.BaseActivity;
import com.novabluetooth.views.TestActivity;

import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Color;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.TextView;

/**
 * 重点人群
 *
 * @author nova
 */
public class FocusGroupMainActivity extends BaseActivity {
    private GridView gd_menu;
    private FocusGroupGridAdapter menuAdapter;
    private TextView tv_name;

    private ARCHIVE_BASEINFO userInfo = null;
    /**
     * 人群分类
     */
    public boolean isChild = false;// 儿童
    public boolean isPregnant = false;// 孕妇
    public boolean isOlder = false;// 老人
    public boolean isPsychosis = false;// 精神病
    public boolean isHypertension = false;// 高血压
    public boolean isDiabetes = false;// 糖尿病
    public boolean isCHD = false;// 冠心病
    public boolean isStroke = false;// 脑卒中
    public boolean isHandicapped = false;// 残疾人
    public boolean isFJH = false;// 肺结核
    public boolean isFeiXinBing=false;//
    public boolean isLeiFengShi=false;
    public boolean isManZuFei=false;
    public boolean isFengShiBing=false;

    @Override
    public Resources getResources() {
        return AdaptScreenUtils.adaptWidth(super.getResources(), 840);
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.focusgroup_main);
        userInfo = NovaApplication.getUserInfo();
        try {
            getGroup();
        } catch (Exception e) {
            e.printStackTrace();
        }

        findViews();
        setListeners();
    }

    public void getGroup() {
        List<String> popList = new ArrayList<String>();
        if (!TextUtils.isEmpty(userInfo.getPOPULATION_TYPE())) {
            String popStr = NovaApplication.getUserInfo().getPOPULATION_TYPE();
            String[] pops = popStr.split(",");
            popList = Arrays.asList(pops);
        }
        isChild = popList.contains("2");
        isPregnant = popList.contains("3");
        isOlder = popList.contains("4");
        isPsychosis = popList.contains("5");
        isHypertension = popList.contains("6");
        isDiabetes = popList.contains("7");
        isCHD = popList.contains("8");
        isStroke = popList.contains("9");
        isHandicapped = popList.contains("10");
        isFJH = popList.contains("11");
        // isChild = true;
        // isPregnant = true;
        // isOlder = true;
        // isPsychosis = true;
        // isHypertension = true;
        // isDiabetes = true;
        // isCHD = true;
        // isStroke = true;
        // isHandicapped = true;

    }

    public void findViews() {
        int i = Color.WHITE;
        tv_name = (TextView) findViewById(R.id.tv_name);
        tv_name.setText("欢迎  " + userInfo.getCUSTOMERNAME());
        gd_menu = (GridView) findViewById(R.id.gd_menu);
        menuAdapter = new FocusGroupGridAdapter(getApplicationContext());
        gd_menu.setAdapter(menuAdapter);
    }

    public void setListeners() {
        // 菜单选项
        gd_menu.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                // 0"孕妇", 1"儿童", 2"老年人", 3"高血压", 4"糖尿病",
                // 5"精神疾病", 6"脑卒中", 7"冠心病", 8"返回"
                Intent intent = null;
                String str_jddwno = SPUtil.getStrjddwno(mContext);
				if (position == 0) {
					// 0 孕妇
					if (isPregnant) {
						intent = new Intent(getApplicationContext(), MaternityActivity.class);
					} else {
						showTextDialog("您不是孕妇");
					}

				} else if (position == 1) {
					// 1 儿童
					if (isChild) {
						intent = new Intent(getApplicationContext(), ChildActivity.class);
					} else {
						showTextDialog("您不是儿童");
					}

				} else if (position == 2) {
					// 2 老年人
					if (isOlder) {
						intent = new Intent(getApplicationContext(), OlderActivity.class);
					} else {
						showTextDialog("您不是老年人");
					}

				} else if (position == 3) {
					// 3"高血压
					if (isHypertension) {
						intent = new Intent(getApplicationContext(), GXYActivity.class);
					} else {
						showTextDialog("您不是高血压患者");
					}

				} else if (position == 4) {
					// 4"糖尿病
					if (isDiabetes) {
						intent = new Intent(getApplicationContext(), TNBActivity.class);
					} else {
						showTextDialog("您不是糖尿病患者");
					}

				} else if (position == 5) {
					// 5"精神疾病
					if (isPsychosis) {
						intent = new Intent(getApplicationContext(), JSJBctivity.class);
					} else {
						showTextDialog("您不是精神疾病患者");
					}

				} else if (position == 6) {
					// 6"脑卒中"
					if (isStroke) {
						intent = new Intent(getApplicationContext(), NCZActivity.class);
					} else {
						showTextDialog("您不是脑卒中患者");
					}

				} else if (position == 7) {
					// 7"冠心病"
					if (isCHD) {
						intent = new Intent(getApplicationContext(), GXBActivity.class);
					} else {
						showTextDialog("您不是冠心病患者");
					}

				} else if (position == 8) {
					if (isFJH) {
						intent = new Intent(getApplicationContext(), FJHActivity.class);
					}else {
						showTextDialog("您不是肺结核患者");
					}
				}else  if (position == 9) {
//                    if("63".equals(str_jddwno.substring(0,2))){
                    intent = new Intent(getApplicationContext(), ManZuFeiActivity.class);
//                        intent = new Intent(getApplicationContext(), FeiXinBingActivity.class);
//                    }else{
//                        FocusGroupMainActivity.this.finish();
//                    }


				}else if(position == 10){
                    intent = new Intent(getApplicationContext(), TestActivity.class);
                    intent.putExtra("type","1");
                }else if(position == 11){
                    intent = new Intent(getApplicationContext(), TestActivity.class);
                    intent.putExtra("type","5");
                }else if(position == 12){
                    intent = new Intent(getApplicationContext(), TestActivity.class);
                    intent.putExtra("type","2");
                }else if(position == 13){
                    intent = new Intent(getApplicationContext(), TestActivity.class);
                    intent.putExtra("type","3");
                }else if(position == 14){
                    intent = new Intent(getApplicationContext(), TestActivity.class);
                    intent.putExtra("type","4");
                }else if(position == 15){
                    intent = new Intent(getApplicationContext(), TestActivity.class);
                    intent.putExtra("type","6");
                }
//				else  if (position ==10) {
//                    intent = new Intent(getApplicationContext(), LeiFengShiActivity.class);
//                }else  if (position ==11) {
//                    intent = new Intent(getApplicationContext(), ManZuFeiActivity.class);
//                }else  if (position ==12) {
//                    intent = new Intent(getApplicationContext(), FengShiBingActivity.class);
//                }else  if (position == 13) {
//                    FocusGroupMainActivity.this.finish();
//                }

				if (intent != null) {
						startActivity(intent);
				}


//                if (position == 0) {
//                    // 2 老年人
//                    if (isOlder) {
//                        intent = new Intent(getApplicationContext(), OlderActivity.class);
//                    } else {
//                        showTextDialog("您不是老年人");
//                    }
//
//                } else if (position == 1) {
//                    // 3"高血压
//                    if (isHypertension) {
//                        intent = new Intent(getApplicationContext(), GXYActivity.class);
//                    } else {
//                        showTextDialog("您不是高血压患者");
//                    }
//
//                } else if (position == 2) {
//                    // 4"糖尿病
//                    if (isDiabetes) {
//                        intent = new Intent(getApplicationContext(), TNBActivity.class);
//                    } else {
//                        showTextDialog("您不是糖尿病患者");
//                    }
//                } else if (position == 3) {
//                    // 儿童
//                    if (isPsychosis) {
//						intent = new Intent(getApplicationContext(), JSJBctivity.class);
//					} else {
//						showTextDialog("您不是精神疾病患者");
//					}
//                } else if (position == 4) {
//                    FocusGroupMainActivity.this.finish();
//                }
//                if (intent != null) {
//                    startActivity(intent);
//                }

            }
        });

    }

}
